package com.ltmonitor.web.controller.command;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ltmonitor.entity.TerminalCommand;
import com.ltmonitor.service.JT808Constants;
import com.ltmonitor.web.util.JsonMessage;

/**
 * 信息服务下发
 * 
 */
@Controller
@RequestMapping("/sendInformation")
public class SendInformationAction extends TerminalCommandAction {
	
	@RequestMapping("/view.action")
	public String view(long vehicleId, Model m) {
		m.addAttribute("vehicleId", vehicleId);
		return "/command/sendInformation";
	}

	/**
	 * 发送信息服务下发指令
	 * @param vehicleId
	 * @param configType  信息类型
	 * @param textContent 下发的文本内容
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/send.action")
	public JsonMessage  execute(long vehicleId,int configType, String textContent) {
		try {
			TerminalCommand tc = new TerminalCommand();
			tc.setCmdType(JT808Constants.CMD_INFORMATION);
			tc.setCmdData(configType + ";" + textContent);
			tc.setCmd("" + configType);
			tc.setVehicleId(vehicleId);
			SendCommand(tc);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			return json(false, ex.getMessage());
		}
	}


}
